package com.sleep.psy.external_server.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Objects;


@Component
public class TisFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("输出请求服务器主机IP:" + servletRequest.getRemoteHost()+ "--" + servletRequest.getParameter("token"));
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        System.out.println("获取到的token = " + req.getHeader("token"));

        // 这里处理token
//        if(req.getHeader("token") != null){
//            Long userId = getUserId(req.getHeader("token"));
//            UserInfoRes userInfoRes = new UserInfoRes();
//            userInfoRes.setUserId(userId);
//            req.setAttribute("currentUser", userInfoRes);
//        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }

}
